package com.example.chirdrenserver.controller.AdminController;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.chirdrenserver.Authority.Authority;
import com.example.chirdrenserver.Pojo.dto.BasePage;
import com.example.chirdrenserver.Pojo.dto.admin.AdminPostUpdateDTO;
import com.example.chirdrenserver.Pojo.entity.Post;
import com.example.chirdrenserver.Pojo.vo.admin.AdminPostVO;
import com.example.chirdrenserver.Service.AdminService.AdminPostService;
import com.example.chirdrenserver.Utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.List;

/**
 * @Author: Yu
 * @CreateTime: 2025-06-30
 * @Description:
 */

@RestController
@RequestMapping("/admin/posts")
public class AdminPostController {
    @Autowired
    AdminPostService adminPostService;
    @PostMapping(("/list"))
    @Authority(authority= "permission:post")
    public Result listPost(BasePage basePage) {
       Collection<AdminPostVO> postList= adminPostService.listPost(basePage);
        return Result.success(postList);
    }

    @PostMapping("/update")
    @Authority(authority= "permission:post")
    public Result updatePost(@RequestBody AdminPostUpdateDTO postUpdateDTO) {

        adminPostService.updatePost(postUpdateDTO);
        return Result.success();
    }
    @GetMapping("/{id}")
    @Authority(authority= "permission:post")
    public Result PostInfo(@PathVariable Integer id) {
        AdminPostVO info = adminPostService.getInfoById(id);
        return Result.success(info);
    }

    /**
     * 根据postTit搜索
     * @param postTit
     * @return
     */
    @PostMapping ("/search")
    @Authority(authority= "permission:post")
    public Result LikePost(String postTit) {
        Collection<AdminPostVO> info=adminPostService.getPostLike(postTit);

        return Result.success(info);
    }
    @DeleteMapping("/id")
    @Authority(authority= "permission:post")
    public Result deletePost(@PathVariable Integer id) {
        adminPostService.delete(id);
        return Result.success();
    }
}
